﻿Public Class RenameDialog
    Public imagerename As Boolean
    Public lastname As String
    Public ext As String
    Dim path = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\Gadget Creator\tmp\"

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Me.Close()
    End Sub

    Private Sub RenameDialog_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.ActiveControl = TextBox1
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If imagerename = True Then
            If System.IO.File.Exists(path + TextBox1.Text + ext) = True Then
                MsgBox("This file already exists! Create new file name!", 48, "File alredy exists")
            Else
                Try
                    My.Computer.FileSystem.RenameFile(lastname, TextBox1.Text + ext)
                    ImageViewer.Text = path + TextBox1.Text + ext
                Catch ex As Exception
                    MsgBox(ex.Message)
                    Exit Sub
                End Try

                GeneralForm.refreshfiles()
                Me.Close()
            End If
        Else
            If System.IO.File.Exists(path + TextBox1.Text + ext) = True Then
                MsgBox("This file already exists! Create new file name!", 48, "File alredy exists")
            Else
                Try
                    My.Computer.FileSystem.RenameFile(lastname, TextBox1.Text + ext)
                    GeneralForm.tabcontrol.SelectedTab.Text = TextBox1.Text + ext
                    GeneralForm.tabcontrol.SelectedTab.Name = TextBox1.Text + ext
                Catch ex As Exception
                    MsgBox(ex.Message)
                    Exit Sub
                End Try

                GeneralForm.refreshfiles()
                Me.Close()
            End If
        End If
    End Sub

End Class